package www.lagou.app;

import org.junit.jupiter.api.Test;
import www.lagou.dao.EmployeeDao;
import www.lagou.entity.Dept;
import www.lagou.entity.Employee;

import java.sql.SQLException;
import java.util.List;
import java.util.Optional;

/**
 * 作业3：查询员工信息
 *
 * @author Shuxian Huang
 */
public class TestEmployee {

    EmployeeDao em = new EmployeeDao();

    //查询所有的员工信息 (不包含没有部门的员工)
    @Test
    public void test1() throws SQLException {

        String sql = "select * from employee where did is not null";

        List<Employee> employees = em.findEmployees(sql);

        for (Employee employee : employees) {
            System.out.println(employee);
        }
    }

    //查询每个员工的 姓名, 薪资 和 所属部门名称
    @Test
    public void test2() throws SQLException {
        String sql = "select * from employee";

        List<Employee> employees = em.findEmployees(sql);

        for (Employee employee : employees) {
            Dept dept = employee.getDept();
            System.out.println("name:" + employee.getName() + ", salary:" + employee.getSalary()
                + ", deptName:" + (dept == null ? null : dept.getDeptName()));
        }
    }
}
